package com.stu.manager.studentscoremanagersys.controller;

import com.stu.manager.studentscoremanagersys.pojo.Score;
import com.stu.manager.studentscoremanagersys.req.ComonListRequest;
import com.stu.manager.studentscoremanagersys.req.ReqScoreAdd;
import com.stu.manager.studentscoremanagersys.req.ReqScoreUpdate;
import com.stu.manager.studentscoremanagersys.res.Result;
import com.stu.manager.studentscoremanagersys.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/score")
public class ScoreHandler {

    @Autowired
    ScoreService scoreService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated ReqScoreAdd scoreAdd){
        scoreService.add(scoreAdd);
        return Result.buildScuess("添加成绩成功");
    }

    @PostMapping("/selectPage")
    public Result<List<Score>> selectPage(@RequestBody @Validated ComonListRequest commonlist){
        return scoreService.selectPage(commonlist);
    }

    @GetMapping("/deleteById")
    public Result<String> deleteById(Long id){
        return scoreService.deleteById(id);
    }

    @GetMapping("/selectById")
    public Result<Score> selectById(Long id){
        return scoreService.selectById(id);
    }

    @PostMapping("/updateById")
    public Result<String> updateById(@RequestBody @Validated ReqScoreUpdate update){
        return scoreService.updateById(update);
    }

}
